'''
database_connector
Attention:
    If you want insert one entry, paramters should be reseted first.
    Or the entry you insert is the oldder one. And exception will be
    raised if some limit is set on your database such as unique.
Dump is a useful method, but not finished yet.
'''
import MySQLdb

class DatabaseConnector:
    __conn = None
    __cursor = None
    __sql = ''
    __param = None
    
    __remoteIP = ''
    __remoteUser = ''
    __remotePasswd = ''
    __remoteDatabase = ''
    
    def __init__(self, ip, user, passwd, database):
        self.__remoteIP = ip
        self.__remoteUser = user
        self.__remotePasswd = passwd
        self.__remoteDatabase = database

    def __del__():
        if self.__cursor:
            self.__cursor.close()
        if self.__conn:
            self.__conn.close()

    def connect():
        try:
            self.__conn = MySQLdb.connect(__remoteIP, __remoteUser, __remotePasswd, __remoteDatabase)
            self.__cursor = self.__conn.cursor()
        except:
            raise
        finally:
            self.__del()__

    def setSql(sql):
        self.__sql = sql

    def setParam(param):
        self.__param = param

    def insertOneEntry():
        try:
            cursor.execute(self.__sql, self.__param)
        except:
            raise


